IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'sprDelete_Concept')
	BEGIN
		DROP  Procedure  dbo.sprDelete_Concept
	END

GO

CREATE Procedure dbo.sprDelete_Concept
	@conceptLSID nvarchar(300),
	@newConceptLSID nvarchar(300),
	@user nvarchar(50)
AS

	
	if (not exists(  select * 
					from tblConceptRelationship 
					inner join tblConcept on ConceptPk = ConceptRelationshipConcept1Fk 
					where ConceptLsid = @conceptLsid )
		and not exists(  select * 
					from tblConceptRelationship 
					inner join tblConcept on ConceptPk = ConceptRelationshipConcept2Fk 
					where ConceptLsid = @conceptLsid ) )					
	begin		
		insert into tblDeprecated
		select @conceptLsid, @newConceptLsid, 'tblConcept', getdate(), @user
	end
	else
	begin
		raiserror ('Concept caanot be deprecated as it has ConceptRelationships linking to it.', 16, 1)
	end
	
GO

GO


GRANT EXEC ON dbo.sprDelete_Concept TO PUBLIC

GO


